﻿using Super.Admin.EFCore;
using Super.Admin.Entities;
using Super.Admin.IServices;
using System.Text;

namespace Super.Admin.Services
{
    /// <summary>
    /// 图标服务实现类
    /// </summary>
    public class IconService : BaseService, IIconService
    {

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="context">操作的数据库上下文</param>
        public IconService(SuperDataBaseDbContext context) : base(context) { }
        /// <summary>
        /// 获得所有图标
        /// </summary>
        /// <returns>图标实体集合</returns>
        public IReadOnlyCollection<IconEntity> GetIcons()
        {
            return Query<IconEntity>(i => true).ToList();
        }
        /// <summary>
        /// 创建图标
        /// </summary>
        /// <param name="iconName">图标名称</param>
        /// <param name="iconValue">图标值 一般用byte存储</param>
        public void CreateIcon(string iconName, byte[] iconValue)
        {
            if (string.IsNullOrEmpty(iconName))
            {
                iconName = Encoding.UTF8.GetString(iconValue);
            }
            IconEntity icon = new IconEntity { Name = iconName, Value = iconValue };
            Insert<IconEntity>(icon);
            base.Commit(); // 提交事务
        }
    }
}
